
package Connection;

import Controllers.Application;
import Entities.World;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;


public class FileWorldCreator implements WorldCreator{

    private String path = "C:/WorldList/";
    private Application application;
    
    public FileWorldCreator(Application application){
        this.application = application;
    }
    
    @Override
    public String[] createEmptyWorld() {
        File folder = new File(path);
        File newWorld = new File(path+folder.list().length);
        try {
            newWorld.mkdir();
            World world = new World("/Images/world.png", folder.list().length-1, false);
            File file = new File(path+(folder.list().length-1)+"/worldDescriptor.txt");
            FileOutputStream oStream = new FileOutputStream(file);
            ObjectOutputStream o = new ObjectOutputStream(oStream);
            o.writeObject(world);
            o.flush();
            o.close();
            
        } catch (Exception ex) {
            try {
                File file = new File("C:/CreateWorldFile_createEmptyWorld.txt");
                file.createNewFile();
            } catch (IOException ex1) {
                Logger.getLogger(FileWorldCreator.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
        return folder.list();
    }
}
